<?php
namespace Home\Model;
use Think\Model;
    class GoodsModel extends Model {       
        
        //根据查询条件显示相应的商品
        public function getByFilter($field,$where)//$field查询的字段列表，gid,gname,price  $where 查询的条件
        {
            //获取地址栏上的参数，SQL转义
           $filter=array_map(array($this->db,'escapeString'),I('get.'));
           $cid=$where['cid'];
           $order='gid desc';
           if (isset($filter['order']))
           {
                if ($filter['order']=='price_asc')
                    $order="price asc";
        
                if ($filter['order']=='price_desc')
                    $order="price desc";  
           }
           if (isset($filter['min_p']))
           {
               $where[]='price >='. (int)$filter['min_p'];
           }
           if (isset($filter['max_p']) && $filter['max_p']!=0)
           {
               $where[]='price <='. (int)$filter['max_p'];
           }
           //按条件查询
           $goodslist=$this->field($field)->where($where)->order($order)->select();
           return $goodslist;
        }
    }

